package com.cxyd.modules.wms.controller;
import com.cxyd.common.page.PageData;
import com.cxyd.common.utils.Result;
import com.cxyd.common.Utils.ExcelUtils;
import com.cxyd.common.annotation.LogOperation;
import com.cxyd.modules.log.excel.SysLogWorkExcel;
import com.cxyd.modules.wms.dto.LogWorkDTO;
import com.cxyd.modules.wms.service.LogWorkService;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletResponse;
import java.util.List;
import java.util.Map;


/**
 * 日志信息
 *
 */
@RestController
@RequestMapping("wms/log-work")
public class LogWorkController {
    private final LogWorkService logWorkService;

    public LogWorkController(LogWorkService logWorkService) {
        this.logWorkService = logWorkService;
    }

    @GetMapping("page")
    @RequiresPermissions("wms:log-work:page")
    public Result<PageData<LogWorkDTO>> page(@RequestParam Map<String, Object> params){
        PageData<LogWorkDTO> page = logWorkService.page(params);

        return new Result<PageData<LogWorkDTO>>().ok(page);
    }

    @GetMapping("{id}")
    @RequiresPermissions("wms:log-work:info")
    public Result<LogWorkDTO> get(@PathVariable("id") Long id){
        LogWorkDTO data = logWorkService.get(id);

        return new Result<LogWorkDTO>().ok(data);
    }

    @GetMapping("export")
    @LogOperation("导出")
    @RequiresPermissions("wms:log-work:export")
    public void export(@RequestParam Map<String, Object> params, HttpServletResponse response) throws Exception {
        List<LogWorkDTO> list = logWorkService.list(params);

        ExcelUtils.exportExcelToTarget(response, null, list, SysLogWorkExcel.class);
    }

}
